package com.shijunhao.graduation.enums;


import com.baomidou.mybatisplus.core.conditions.AbstractWrapper;
import com.baomidou.mybatisplus.core.conditions.interfaces.Compare;
import com.shijunhao.graduation.handler.mybatisplus.IBindingCondition;

import java.util.ArrayList;
import java.util.List;

/**
 * @author: shijunhao
 * @date: 2022/3/5 16:38
 * @description:
 */
public enum SqlSymbol {
    EQ(Compare::eq, "等于"),
    NE(Compare::ne, "不等于"),
    GT(Compare::gt, "大于"),
    GE(Compare::ge, "大于等于"),
    LT(Compare::lt, "小于"),
    LE(Compare::le, "小于等于"),
    LIKE(Compare::like, "模糊匹配"),
    NOT_LIKE(Compare::notLike, "模糊不匹配"),
    LIKE_LEFT(Compare::likeLeft, "模糊匹配左侧"),
    LIKE_RIGHT(Compare::likeRight, "模糊匹配右侧"),
    BETWEEN((AbstractWrapper wrapper, String col, Object value) -> {
        List<Object> val = (ArrayList) value;
        if (val != null && val.size() == 2)
            wrapper.between(true, col, val.get(0), val.get(1));
    }, "介于");

    private IBindingCondition binding;
    private String label;

    SqlSymbol(IBindingCondition binding, String label) {
        this.binding = binding;
        this.label = label;
    }

    public String getLabel() {
        return label;
    }

    public IBindingCondition getBinding() {
        return binding;
    }
}
